﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using ASPNETPerformance.App_BusinessLogic.Helpers;
using ASPNETPerformance.App_BusinessLogic.Utils;

namespace ASPNETPerformance.App_BusinessLogic.StaticPage {
    public class StaticPageManager {

        public static void RemoveOutputCache() {
            // 更新文件
            foreach ( var file in Directory.GetFiles( HttpRuntime.AppDomainAppPath + "Temp" ) ) {
                File.Delete( file );
            }

            // 删除缓存
            HttpResponse.RemoveOutputCacheItem( CommonHelper.RelativeWebRoot + "DiskCache.aspx" );
        }

        public static string GetGenerationTemplateHTML() {
            string path = HttpRuntime.AppDomainAppPath + "05_StaticPage\\GenerationTemplate.html";
            if ( !File.Exists( path ) )
                return null;

            FileStream fs = null;
            fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read );

            if ( fs == null )
                throw new IOException( "无法打开文件: " + path );

            StreamReader sr = new StreamReader( fs, UTF8Encoding.UTF8 );
            string res = sr.ReadToEnd();
            sr.Close();
            return res;
        }

        public static void SaveGenerationStaticPage( string path, string content ) {
            FileStream fs = null;
            fs = new FileStream( path, FileMode.Create, FileAccess.Write, FileShare.None );
            if ( fs == null )
                throw new IOException( "无法打开文件: " + path );
            StreamWriter sw = new StreamWriter( fs, UTF8Encoding.UTF8 );
            sw.Write( content );
            sw.Close();
        }

        public static List<CategoryBreadCrumbsHelperClass> GetGenerationCategoryBreadCrumbsData() {
            var result = new List<CategoryBreadCrumbsHelperClass>
                             {
                                 new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName = "配饰"
                                     },

                                    new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName =  "钟表"
                                     },
                                    new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName =  "手表"
                                     },
                                    new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName = "女士手表"
                                     },
                                       new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName = "休闲表"
                                     },
                                       new CategoryBreadCrumbsHelperClass
                                     {
                                         CategoryName = "石英表"
                                     },

                             };
            return result;
        }

        public static List<ProductImagesHelperClass> GetGenerationProductImagesData() {
            var result = new List<ProductImagesHelperClass>
                             {
                                 new ProductImagesHelperClass
                                     {
                                         ImageUrl =
                                             "http://p.ytrss.com/product/07/015/000a/smallimage/2010121017271489.jpg"
                                     },

                                    new ProductImagesHelperClass
                                     {
                                         ImageUrl =
                                             "http://p.ytrss.com/product/07/015/000a/smallimage/2010121017272316.jpg"
                                     },
                                    new ProductImagesHelperClass
                                     {
                                         ImageUrl =
                                             "http://p.ytrss.com/product/07/015/000a/smallimage/2010121017272924.jpg"
                                     },
                                    new ProductImagesHelperClass
                                     {
                                         ImageUrl =
                                             "http://p.ytrss.com/product/07/015/000a/smallimage/2010121017273517.jpg"
                                     },

                             };
            return result;
        }

        public static List<ProductHelperClass> GetGenerationProductsData() {
            var result = new List<ProductHelperClass>
                             {
                                 new ProductHelperClass
                                     {
                                         ItemCode = "07-015-000AC",
                                          Price =  1955,
                                          PriceOld = 1955,
                                          SKU="07-015-000A",
                                          Stock = 100,
                                          Title="GUESS可换表带套装女表/W11130L1"
                                     },
                             };
            return result;
        }
    }
}